Interactive UI in PHP & Twig
Add Live Components to your app.
Build dynamic interfaces with zero JavaScript
// ... use statements hidden - click to show
#[AsLiveComponent('SearchPackages', template: 'components/Package/SearchPackages.html.twig')]
final class SearchPackages
{
use DefaultActionTrait;
#[LiveProp(writable: true, url: true)]
public ?string $query = null;
public function __construct(private UxPackageRepository $packageRepo)
{
}
/**
* @return list<\App\Model\UxPackage>
*/
public function getPackages(): array
{
return $this->packageRepo->findAll($this->query);
}
}
<div{{ attributes }}>
<twig:Form:Input type="text" data-model="query" placeholder="Results update as you type..." />
<div class="pt-3 grid gap-2 grid-cols-[repeat(auto-fill,minmax(260px,1fr))]" data-loading="addClass(opacity-50)">
{% for package in computed.packages %}
<twig:PackageListItem package="{{ package }}" titleTag="h4" />
{% else %}
No packages found "{{ query }}"
{% endfor %}
</div>
</div>
Live Components